package com.example.xianji.fragment;

import java.util.ArrayList;
import java.util.HashMap;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.JsonObjectRequest;
import com.example.xianji.Contant;
import com.example.xianji.XJApplication;
import com.example.xianji.activity.Main_LoginActivity;
import com.example.xianji.activity.Main_QiYe_RuZhuActivity;
import com.example.xianji.activity.Main_SearchActivity;
import com.example.xianji.activity.Main_Send_Want_Buy_ProductActivity;
import com.example.xianji.activity.Main_geren_send_fuwuActivity;
import com.example.xianji.R;
import com.example.xianji.adapter.ErJi_FuWuFenlei_Adapter;
import com.example.xianji.adapter.FuWu_Adapter;
import com.example.xianji.adapter.FuWu_FenLei_Adapter;
import com.example.xianji.adapter.PlaceAdapter;
import com.example.xianji.BGARefresh.BGANormalRefreshViewHolder;
import com.example.xianji.BGARefresh.BGARefreshLayout;
import com.example.xianji.BGARefresh.BGARefreshLayout.BGARefreshLayoutDelegate;
import com.example.xianji.constant.Constant;
import com.example.xianji.eventbus.FirstEventBus;
import com.example.xianji.bean.FuWu;
import com.example.xianji.bean.Place;
import com.example.xianji.bean.YiJi_Class;

import com.example.xianji.utils.sp.PreferenceEngine;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
/**
 * 服务大厅
 * @author me
 *
 */
public class FuWu_Fragment extends Fragment implements
		BGARefreshLayoutDelegate, OnClickListener {
	/************************** 服务大厅 ********************************/
	private BGARefreshLayout fuwu_refreshlayout;
	private ListView fuwu_my_listview;
	private FuWu_Adapter mFuWu_Adapter;// 服务大厅列表适配器
	private ArrayList<Integer> list;
	private ImageView fuwu_search, fuwu_image_load;
	private ArrayList<FuWu> fuwu_list = new ArrayList<FuWu>();// 服务列表数据集合
	private int page = 1;
	// private CustomProgressDialog mCustomProgressDialog;
	private RelativeLayout fuwu_place, relativelayout_fuwu_class,
			fuwu_send_fuwu, relativelayout_fuwu_back, fuwu_send_want_buy;
	private LinearLayout layout2, show_popoupwindow_location, layout,
			linearlayout_listview;
	private GridView province_gridview;
	private PopupWindow show_popupWindow;
	public boolean fuwu_province_click_flag = false,
			fuwu_fenlei_click_flag = false;
	public String fuwu_province_name = "地区", fuwu_class_name = "服务分类";
	public String fuwu_province_id, fuwu_class_id, erji_id;
	private ArrayList<Place> place_list = new ArrayList<Place>();
	private PlaceAdapter mPlaceAdapter;
	private TextView text_fuwu_place, text_fuwu_class_name, service_title;
	private ListView yiji_listview, erji_listview;
	private ArrayList<YiJi_Class> fuwu_fenlei_list = new ArrayList<YiJi_Class>();
	private FuWu_FenLei_Adapter mFuWu_FenLei_Adapter;// 服务分类一级适配器
	private ErJi_FuWuFenlei_Adapter mErJi_FuWuFenlei_Adapter;// 服务分类二级适配器
	private ArrayList<YiJi_Class> erji_fenlei_list = new ArrayList<YiJi_Class>();
	private View view;
	private AnimationDrawable fuwu_animation_drawable;
	private View fuwu_translation_view;
	public static String text_fuwu_content = "";
    //	private SharedPreferences sp;
//	private Editor ed;
	private Handler handler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			if (msg.what == 1) {
				fuwu_my_listview.setAdapter(mFuWu_Adapter);
				fuwu_refreshlayout.endRefreshing();

				fuwu_animation_drawable.stop();
				fuwu_image_load.setVisibility(View.GONE);
			}
			if (msg.what == 2) {
				mFuWu_Adapter.notifyDataSetChanged();
				fuwu_refreshlayout.endLoadingMore();
				// fuwu_PullToRefreshView.onFooterRefreshComplete();
			}

			if (msg.what == 3) {

				erji_listview.setAdapter(mErJi_FuWuFenlei_Adapter);

				erji_listview.setOnItemClickListener(new OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> arg0, View arg1,
							int arg2, long arg3) {
						erji_id = erji_fenlei_list.get(arg2).getId() + "";
						text_fuwu_class_name.setText(erji_fenlei_list.get(arg2)
								.getName());
						fuwu_fenlei_click_flag = true;
						hide();
						XJApplication.cachThreadPool.execute(new Runnable() {

							@Override
							public void run() {
								get_service_data();
							}
						});

					}
				});
			}
		}
	};

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.fuwu_layout, container, false);
		init();
		setListener();
		processLogic(savedInstanceState);
		XJApplication.cachThreadPool.execute(new Runnable() {

			@Override
			public void run() {
				get_service_data();
			}
		});
		return view;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		if (text_fuwu_content.length() > 0) {
			service_title.setText(text_fuwu_content);
		} else {
			service_title.setText("服务大厅");
		}
		text_fuwu_class_name.setText(fuwu_class_name);
		text_fuwu_place.setText(fuwu_province_name);

		if(!EventBus.getDefault().isRegistered(this)){
			EventBus.getDefault().register(this);
		}
	}

	public void init() {
		fuwu_refreshlayout = (BGARefreshLayout) view
				.findViewById(R.id.fuwu_refreshlayout);
		fuwu_my_listview = (ListView) view.findViewById(R.id.fuwu_my_listview);
		mFuWu_Adapter = new FuWu_Adapter(getActivity(), fuwu_list);
		fuwu_search = (ImageView) view.findViewById(R.id.fuwu_search);
		fuwu_place = (RelativeLayout) view.findViewById(R.id.fuwu_place);
		show_popoupwindow_location = (LinearLayout) view
				.findViewById(R.id.show_popoupwindow_location);
		text_fuwu_place = (TextView) view.findViewById(R.id.text_fuwu_place);
		relativelayout_fuwu_class = (RelativeLayout) view
				.findViewById(R.id.relativelayout_fuwu_class);
		text_fuwu_class_name = (TextView) view
				.findViewById(R.id.text_fuwu_class_name);
		service_title = (TextView) view.findViewById(R.id.service_title);
		fuwu_image_load = (ImageView) view.findViewById(R.id.fuwu_image_load);
		fuwu_animation_drawable = (AnimationDrawable) fuwu_image_load
				.getDrawable();
		fuwu_animation_drawable.start();
		yiji_listview = (ListView) view
				.findViewById(R.id.expanable_yiji_listview);
		erji_listview = (ListView) view
				.findViewById(R.id.expanable_erji_listview);
		province_gridview = (GridView) view
				.findViewById(R.id.province_gridview);
		linearlayout_listview = (LinearLayout) view
				.findViewById(R.id.linearlayout_listview);
		fuwu_translation_view = view.findViewById(R.id.fuwu_translation_view);
		fuwu_send_fuwu = (RelativeLayout) view
				.findViewById(R.id.fuwu_send_fuwu);
		relativelayout_fuwu_back = (RelativeLayout) view
				.findViewById(R.id.relativelayout_fuwu_back);
		fuwu_send_want_buy = (RelativeLayout) view
				.findViewById(R.id.fuwu_send_want_buy);

//		sp = getActivity().getSharedPreferences("text",
//				getActivity().MODE_PRIVATE);
//		ed = sp.edit();
	}

	public void setListener() {
		fuwu_refreshlayout.setDelegate(this);
		fuwu_search.setOnClickListener(this);
		relativelayout_fuwu_class.setOnClickListener(this);
		fuwu_place.setOnClickListener(this);
		fuwu_translation_view.setOnClickListener(this);
		fuwu_send_fuwu.setOnClickListener(this);
		relativelayout_fuwu_back.setOnClickListener(this);
		fuwu_send_want_buy.setOnClickListener(this);

	}

	public void processLogic(Bundle savedInstanceState) {

		fuwu_refreshlayout.setRefreshViewHolder(new BGANormalRefreshViewHolder(
				getActivity(), true));

	}

	@Subscribe(threadMode = ThreadMode.MAIN,sticky = true)
	public void onEventMainThread(FirstEventBus event) {
		/*************** 获取从地区的适配器中的地址和地址id ************************/
		if (event.flag) {
			fuwu_fenlei_click_flag = true;

			text_fuwu_class_name.setText(event.name);
			erji_id = event.id;

			fuwu_class_name = event.name;
			XJApplication.cachThreadPool.execute(new Runnable() {

				@Override
				public void run() {
					get_service_data();
				}
			});
			hide();
		}
	}

	public void get_service_data() {

		HttpUtils httpUtils = new HttpUtils();
		RequestParams parms = new RequestParams();

		parms.addBodyParameter("page", 1 + "");
		parms.addBodyParameter("k", text_fuwu_content);
		parms.addBodyParameter("cid", erji_id);

		parms.addBodyParameter("area", fuwu_province_id);

		httpUtils.send(HttpMethod.POST, Contant.fuwu_liebiao, parms,
				new RequestCallBack<String>() {

					@Override
					public void onFailure(HttpException arg0, String arg1) {
						fuwu_refreshlayout.endRefreshing();
						fuwu_animation_drawable.stop();
						fuwu_image_load.setVisibility(View.GONE);
					}

					@Override
					public void onSuccess(ResponseInfo<String> arg0) {
						try {
							JSONObject response = new JSONObject(arg0.result);
							if (response.getInt("status") == 1) {
								fuwu_list.clear();
								JSONArray array = response.getJSONArray("data");

								JSONArray ay = array.getJSONArray(0);

								JSONArray ay1 = array.getJSONArray(1);

								JSONArray ay2 = array.getJSONArray(2);
								if (ay.length() > 0) {
									for (int i = 0; i < ay.length(); i++) {

										JSONObject ob = ay.getJSONObject(i);

										FuWu mFuWu = new FuWu();
										// mFuWu.setCat_name(ob.getString("cat_name"));
										mFuWu.setCity_name(ob
												.getString("city_name"));
										mFuWu.setProvince_name(ob
												.getString("province_name"));
										mFuWu.setTitle(ob.getString("title"));
										Log.i("caseuploads", ob + "");
										mFuWu.setImgurl(ob.getString("imgurl"));

										mFuWu.setBtitle(ob.getString("btitle"));

										mFuWu.setId(ob.getInt("id"));
										mFuWu.setCat_name(ob
												.getString("cat_name"));

										fuwu_list.add(mFuWu);
										mFuWu = null;
									}
								} else {

									Toast.makeText(getActivity(), "暂无数据", Toast.LENGTH_LONG)
											.show();
								}

								Log.i("wwwewwwwww", ay1.length() + "");
								fuwu_fenlei_list.clear();

								for (int i = 0; i < ay1.length(); i++) {
									JSONObject obj1 = ay1.getJSONObject(i);
									YiJi_Class mYiJi_Class = new YiJi_Class();
									mYiJi_Class.setId(obj1.getInt("id"));
									mYiJi_Class.setName(obj1.getString("name"));
									fuwu_fenlei_list.add(mYiJi_Class);

								}

								place_list.clear();
								for (int i = 0; i < ay2.length(); i++) {
									JSONObject ob2 = ay2.getJSONObject(i);
									Place mPlace = new Place();
									mPlace.setArea_id(ob2.getString("area_id"));
									mPlace.setArea_name(ob2
											.getString("area_name"));

									place_list.add(mPlace);
									mPlace = null;

								}
								handler.sendEmptyMessage(1);
							}

						} catch (JSONException e) {
							e.printStackTrace();
						}
					}
				});
	}

	public void get_service_data_more() {
		HttpUtils httpUtils = new HttpUtils();
		RequestParams parms = new RequestParams();
		parms.addBodyParameter("page", page + "");
		parms.addBodyParameter("k", text_fuwu_content);
		parms.addBodyParameter("cid", erji_id);
		parms.addBodyParameter("area", fuwu_province_id);
		httpUtils.send(HttpMethod.POST, Contant.fuwu_liebiao, parms,
				new RequestCallBack<String>() {

					@Override
					public void onFailure(HttpException arg0, String arg1) {
						// fuwu_PullToRefreshView.onFooterRefreshComplete();
						fuwu_refreshlayout.endLoadingMore();
					}

					@Override
					public void onSuccess(ResponseInfo<String> arg0) {
						try {
							JSONObject object = new JSONObject(arg0.result);
							if (object.getInt("status") == 1) {
								JSONArray array = object.getJSONArray("data");
								JSONArray ay = array.getJSONArray(0);
								if (ay.length() > 0) {
									for (int i = 0; i < ay.length(); i++) {
										JSONObject ob = ay.getJSONObject(i);
										FuWu mFuWu = new FuWu();
										mFuWu.setCat_name(ob
												.getString("cat_name"));
										mFuWu.setCity_name(ob
												.getString("city_name"));
										mFuWu.setProvince_name(ob
												.getString("province_name"));
										mFuWu.setTitle(ob.getString("title"));
										mFuWu.setId(ob.getInt("id"));
										mFuWu.setImgurl(ob.getString("imgurl"));
										mFuWu.setBtitle(ob.getString("btitle"));
										fuwu_list.add(mFuWu);
									}
								} else {
									Toast.makeText(getActivity(), "没有更多数据", Toast.LENGTH_LONG)
											.show();
								}
								handler.sendEmptyMessage(2);
							}

						} catch (JSONException e1) {
							e1.printStackTrace();
						}
					}
				});
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.fuwu_search) {
			Intent intent = new Intent(getActivity(), Main_SearchActivity.class);
			intent.putExtra("search", 2);
			getActivity().startActivity(intent);
		}/*
		 * else if (v.getId() == R.id.fuwu_place) {
		 * 
		 * grideview_show(); mPlaceAdapter = new PlaceAdapter(getActivity(),
		 * place_list, 2); province_gridview.setAdapter(mPlaceAdapter);
		 * 
		 * province_gridview.setOnItemClickListener(new OnItemClickListener() {
		 * 
		 * @Override public void onItemClick(AdapterView<?> arg0, View arg1, int
		 * arg2, long arg3) {
		 * 
		 * hide(); mPlaceAdapter.set_selectposition(arg2);
		 * mPlaceAdapter.notifyDataSetChanged();
		 * 
		 * text_fuwu_place .setText(place_list.get(arg2).getArea_name());
		 * 
		 * fuwu_province_name = place_list.get(arg2).getArea_name();
		 * fuwu_province_id = place_list.get(arg2).getArea_id();
		 * 
		 * fuwu_province_click_flag = true;
		 * 
		 * get_service_data(); }
		 * 
		 * });
		 * 
		 * }
		 */else if (v.getId() == R.id.relativelayout_fuwu_class) {

			listview_show();
			mFuWu_FenLei_Adapter = new FuWu_FenLei_Adapter(getActivity(),
					fuwu_fenlei_list);
			mErJi_FuWuFenlei_Adapter = new ErJi_FuWuFenlei_Adapter(
					getActivity(), erji_fenlei_list, 1);

			yiji_listview.setAdapter(mFuWu_FenLei_Adapter);
			// fenlei_class_flag=true;
			yiji_listview.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1,
						int arg2, long arg3) {
					fuwu_class_id = fuwu_fenlei_list.get(arg2).getId() + "";
					mFuWu_FenLei_Adapter.setPosition(arg2);
					mFuWu_FenLei_Adapter.notifyDataSetChanged();
					fuwu_class_name = fuwu_fenlei_list.get(arg2).getName();
					final int a = arg2;
					if (fuwu_fenlei_list.get(arg2).getName().equals("全部")) {
						fuwu_fenlei_click_flag = true;
						text_fuwu_class_name.setText("全部");
						erji_id = fuwu_fenlei_list.get(arg2).getId() + "";
						hide();
						XJApplication.cachThreadPool.execute(new Runnable() {

							@Override
							public void run() {
								get_service_data();
							}
						});

					} else {
						XJApplication.cachThreadPool.execute(new Runnable() {

							@Override
							public void run() {
								get_erji_fuwu_feilei(fuwu_fenlei_list.get(a)
										.getId() + "");
							}
						});
					}
				}
			});

		} else if (v.getId() == R.id.fuwu_translation_view) {
			hide();
		} else if (v.getId() == R.id.fuwu_send_fuwu) {
			// 发布服务点击事件
            if (PreferenceEngine.getInstance().getBoolean(Constant.SP.NAME, Constant.SP.KEY_XIANJI_DENGLU, false)) {
                if (PreferenceEngine.getInstance().getInt(Constant.SP.NAME, Constant.SP.KEY_XIANJI_STATUS, 5) == 1) {
					// 可以申请企业入驻
					getActivity().startActivity(
							new Intent(getActivity(),
									Main_QiYe_RuZhuActivity.class));
                } else if (PreferenceEngine.getInstance().getInt(Constant.SP.NAME, Constant.SP.KEY_XIANJI_STATUS, 5) == 0) {
					Toast.makeText(getActivity(), "正在审核，请耐心等待", Toast.LENGTH_SHORT).show();
                } else if (PreferenceEngine.getInstance().getInt(Constant.SP.NAME, Constant.SP.KEY_XIANJI_STATUS, 5) == 2) {
					// 审核失败，可以再次申请企业入驻
                    getActivity().startActivity(new Intent(getActivity(), Main_QiYe_RuZhuActivity.class));
                } else if (PreferenceEngine.getInstance().getInt(Constant.SP.NAME, Constant.SP.KEY_XIANJI_STATUS, 5) == 3) {
					getActivity().startActivity(
							new Intent(getActivity(),
									Main_geren_send_fuwuActivity.class));
				}
			} else {
				Contant.come_from_fuwuDetail = 1;
				startActivity(new Intent(getActivity(),
						Main_LoginActivity.class));
			}
		} else if (v.getId() == R.id.relativelayout_fuwu_back) {
			getActivity().finish();
		} else if (v.getId() == R.id.fuwu_send_want_buy) {
			// 发布求购点击事件
            if (PreferenceEngine.getInstance().getBoolean(Constant.SP.NAME, Constant.SP.KEY_XIANJI_DENGLU, false)) {
				// 发布
				Intent intent = new Intent(getActivity(),
						Main_Send_Want_Buy_ProductActivity.class);

				intent.putExtra("come_from_fuwu_send_buy",
						Contant.come_from_fuwu_send_buy);

				startActivity(intent);

			} else {
				startActivity(new Intent(getActivity(),
						Main_LoginActivity.class));
			}
		}
	}

	private void listview_show() {
		linearlayout_listview.setVisibility(View.VISIBLE);
		province_gridview.setVisibility(View.GONE);
		fuwu_translation_view.setVisibility(View.VISIBLE);
	}

	private void hide() {
		linearlayout_listview.setVisibility(View.GONE);
		province_gridview.setVisibility(View.GONE);
		fuwu_translation_view.setVisibility(View.GONE);
		refresh_load_stop();
	}

	private void grideview_show() {
		linearlayout_listview.setVisibility(View.GONE);
		province_gridview.setVisibility(View.VISIBLE);
		fuwu_translation_view.setVisibility(View.VISIBLE);
	}

	/**
	 * 二级服务分类
	 * 
	 * @param id
	 */
	public void get_erji_fuwu_feilei(String id) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("cid", id);
		JSONObject params = new JSONObject(map);
		JsonObjectRequest request = new JsonObjectRequest(Method.POST,
				Contant.fuwu_fenlei, params, new Listener<JSONObject>() {

					@Override
					public void onResponse(JSONObject response) {
						try {
							if (response.getInt("status") == 1) {
								erji_fenlei_list.clear();
								JSONArray array = response.getJSONArray("data");

								for (int i = 0; i < array.length(); i++) {
									JSONObject object = array.getJSONObject(i);
									YiJi_Class mYiJi_Class = new YiJi_Class();
									mYiJi_Class.setId(object.getInt("id"));
									mYiJi_Class.setName(object
											.getString("name"));
									mYiJi_Class.setCatethree(object
											.getJSONArray("catethree"));
									erji_fenlei_list.add(mYiJi_Class);
								}
								handler.sendEmptyMessage(3);
							} else {
								Toast.makeText(getActivity(),
										response.getString("msg"), Toast.LENGTH_SHORT).show();
							}
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}
				}, new Response.ErrorListener() {

					@Override
					public void onErrorResponse(VolleyError error) {
						if (show_popupWindow != null) {
							show_popupWindow.dismiss();
							show_popupWindow = null;
						}
					}
				});
		XJApplication.getHttpQueues().cancelAll("abcPost");
		request.setTag("abcPost");
		request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
		XJApplication.getHttpQueues().add(request);
		XJApplication.getHttpQueues().start();

	}

	@Override
	public void onResume() {
		super.onResume();

		if (text_fuwu_content.length() > 0) {
			service_title.setText(text_fuwu_content);
		} else {
			service_title.setText("服务大厅");
		}
		if (Main_SearchActivity.fuwu_search_id == 1) {
			XJApplication.cachThreadPool.execute(new Runnable() {

				@Override
				public void run() {
					get_service_data();
				}
			});

			Main_SearchActivity.fuwu_search_id = 0;
		}

		refresh_load_stop();
		// 来自于服务详情页面的登录成功请求一下是否升级为企业的数据
		if (Contant.come_from_fuwuDetail == 2) {
			get_shengji_company3();
			Contant.come_from_fuwuDetail = 0;
		}
	}

	/**
	 * 判断是否升级为企业用户
	 */
	public void get_shengji_company3() {
		HttpUtils httpUtils = new HttpUtils();
		RequestParams parms = new RequestParams();
        parms.addBodyParameter("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
		httpUtils.send(HttpMethod.POST, Contant.is_shengji_compny, parms,
				new RequestCallBack<String>() {

					@Override
					public void onFailure(HttpException arg0, String arg1) {
						Toast.makeText(getActivity(), "网络异常", Toast.LENGTH_SHORT).show();
					}

					@Override
					public void onSuccess(ResponseInfo<String> arg0) {
						try {
							JSONObject obj = new JSONObject(arg0.result);
							if (obj.getInt("status") == 3) {
								// 如果返回3表明升级企业通过
                                if (PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TYPE, "").equals("FP")
                                        || PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TYPE, "").equals("AP")) {
									// 记录的还是个人 账号
                                    PreferenceEngine.getInstance().putBoolean(Constant.SP.NAME, Constant.SP.KEY_XIANJI_DENGLU, false);
								}
							}
							// 判断 个人升级为企业的标记
                            PreferenceEngine.getInstance().putInt(Constant.SP.NAME, Constant.SP.KEY_XIANJI_STATUS, obj.getInt("status"));
						} catch (JSONException e) {
							e.printStackTrace();
						}

					}
				});
	}

	private void refresh_load_stop() {
		fuwu_refreshlayout.endRefreshing();
		fuwu_refreshlayout.endLoadingMore();
	}

	@Override
	public void onHiddenChanged(boolean hidden) {
		super.onHiddenChanged(hidden);
		if (!hidden) {

			new Handler() {

				@Override
				public void handleMessage(Message msg) {
					super.handleMessage(msg);
					fuwu_refreshlayout.endRefreshing();
					fuwu_refreshlayout.endLoadingMore();
				}

			}.sendEmptyMessage(0);
		}
	}

	@Override
	public void onBGARefreshLayoutBeginRefreshing(BGARefreshLayout refreshLayout) {
		if (fuwu_animation_drawable.isVisible()) {
			fuwu_refreshlayout.endRefreshing();
		} else {
			page = 1;
			XJApplication.cachThreadPool.execute(new Runnable() {

				@Override
				public void run() {
					get_service_data();
				}
			});

		}
	}

	@Override
	public boolean onBGARefreshLayoutBeginLoadingMore(
			BGARefreshLayout refreshLayout) {
		page++;
		XJApplication.cachThreadPool.execute(new Runnable() {

			@Override
			public void run() {
				get_service_data_more();
			}
		});

		return true;
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		handler.removeCallbacksAndMessages(null);
		text_fuwu_content = "";
		EventBus.getDefault().unregister(this);
	}
}
